$(document).ready(function() {	
	bookItemManage();
});

function bookItemManage() {
	bookItems = $("#item_iBookManage");
	bookItems.empty();
	$.ajax({
		type:"post",
		url:"orderFormAction!findOrderByCustomerId",
		//data:{"customerId":6},
		dataType:"json",
		success:function(result){
			//alert(result);
		    if(result == ""){
		    	bookItems.empty();
		    	bookItems.append('<p>无任何信息/p>');
			}else{
				//alert("2222222222");			
				e='<h4 align="center">预订物品管理</h4>';
				var result1 = result.order;
				$.each(result1,function(){
					
				e +='<div class="item_newItem3">'+
					'<img src="'+this.item.picture+'" style="margin-left:24%"></img>'+
					'<div>'+
						'<table class="table">'+
							'<tbody align="center">'+
								'<tr>'+
									'<td>名称</td>'+
									'<td>'+this.item.itemName+'</td>'+
								'</tr>'+
								'<tr>'+
									'<td>价格</td>'+
									'<td>'+this.item.itemPrice+'</td>'+
								'</tr>'+
								'<tr>'+
									'<td>订购数量</td>'+
									'<td>'+this.orderPrice/this.item.itemPrice+'</td>'+
								'</tr>'+
								'<tr>'+
								'<td>订单状态</td>'+
								'<td>等待商家确认</td>'+
								'</tr>'+
							'</tbody>'+
						'</table>'+
					'</div>'+
					'<button class="btn btn-primary" style="margin-left: 32%;" onclick="cancel('+this.orderId+');">取消预订</button>'+
					'</div>';
				
				
				});
				e+='<div style="clear:both;"></div>';
				e+='<div class="pagination" style="margin-left: 25%">'+
				'<ul>'+
					'<li class="previous"><a href="itemShow.jsp"><img src="image/previous.png" /> </a></li>'+
					'<li><a href="itemShow.jsp">1</a></li>'+
					'<li><a href="itemShow.jsp">2</a></li>'+
					'<li><a href="itemShow.jsp">3</a></li>'+
					'<li><a href="itemShow.jsp">4</a></li>'+
					'<li><a href="itemShow.jsp">5</a></li>'+
					'<li><a href="itemShow.jsp">6</a></li>'+
					'<li><a href="itemShow.jsp">7</a></li>'+
					'<li><a href="itemShow.jsp">8</a></li>'+
					'<li><a href="itemShow.jsp">9</a></li>'+
					'<li class="next"><a href="itemShow.jsp"><img src="image/next.png" /> </a></li>'+
				'</ul>'+
			'</div>';
				bookItems.append(e);			
			}
			//重新渲染
		},
		error:function(err){
			alert(err.message);
		}
	});
}
/////////////////////////////////////////////////////////////////////////////////
function cancel(orderId) {//取消预订
	//alert(orderId);
	$.ajax({
		type:"post",
		url:"orderFormAction!deleteOrder",
		data:{"orderId":orderId},
		//dataType:"json",
	});
	alert("成功取消订单");
	bookItemManage();
}